package com.fh.login.token;

import javax.servlet.http.HttpServletRequest;

public class TokenCommons {

    public static final String token_pre="token:";

    //redis中token的是时间

    public static final Long exp_time=30l;
    public static String user_Key_pre="CURRENTUSER:";

    public static String redisToKenKey(String username,String token,String typeName){
       return token_pre+username+":"+typeName+":"+token;
    }
    public static String typeTokenKey(String username,String typeName){
        return token_pre+username+":"+typeName+":*";
    }


    public static String userKey(String userName,String type){
     return user_Key_pre+userName+":"+type;
    }


    public static String getDeviceType(HttpServletRequest request){
       String type=  request.getHeader("User-Agent");
       String typeName="";
        if (type.contains("Android")||type.contains("Linux")) {
            System.out.println("Android移动客户端");
            typeName="Android";
            if (type.contains("MicroMessenger")) {
                System.out.println("微信");
                typeName="MicroMessenger";
            }
        } else if (type.contains("iPhone")) {
            System.out   .println("iPhone移动客户端");
            typeName="iPhone";

        } else if (type.contains("iPad")) {
            System.out.println("iPad客户端");
            typeName="iPad";
        } else if(type.contains("Windows")){
            System.out.println("Windows");
            typeName="Windows";
        }
        return typeName;
    }

    public static String redisTokenKey(String username, String token, String typeName) {
        return token_pre  + username + ":" + typeName + ":" + token;
    }


}
